var dojoConfig={parseOnLoad:true};

var map,
webmapId = "1a40fa5cc1ab4569b79f45444d728067";

require([
"esri/map",
"esri/arcgis/utils",
"esri/dijit/Legend",
"dojo/domReady!"
], function (Map, arcgisUtils, Legend) {
arcgisUtils.createMap(webmapId, "mapDiv").then(function (response) {
map = response.map     

var legend = new Legend({
    map: map,
    layerInfos:(arcgisUtils.getLegendLayers(response))
}, "legendDiv");

legend.startup();
});
});